package epin.fujiajun.data.array;

import epin.fujiajun.data.Array;

import java.util.Random;

/**
 * Created by DELL on 2017/8/15.
 */
public class Number extends Array<Number> {

    private final int num;

    public Number(int num) {
        this.num = num;
    }

    public int getNum() {
        return num;
    }

    @Override
    public String toString() {
        return String.valueOf(num).toString();
    }

    @Override
    public int compareTo(Number o) {
        if (this.num > o.num) return +1;
        if (this.num < o.num) return -1;
        return 0;
    }


    /**
     * <p>构造一条长度为size在range范围内的随机数组</p>
     *
     * @param size
     * @param range
     * @return
     */
    public static Number[] createArray(int size, int range){
        Number[] a = new Number[size];
        Random random = new Random();

        for (int i = 0;i < size;i++){
            Number number = new Number(random.nextInt(range) + 1);
            a[i] = number;
        }

        return a;
    }
}
